package com.boco.modules.fdoc.api;

import java.io.UnsupportedEncodingException;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.boco.common.json.BaseJsonVo;
import com.boco.common.utils.JsonUtils;
import com.boco.common.web.BaseController;
import com.boco.modules.fdoc.model.HospitalEntity;
import com.boco.modules.fdoc.service.HospitalService;
import com.boco.modules.fdoc.vo.HospitalVo;
import com.wordnik.swagger.annotations.ApiOperation;

/**
 * 医院 api
 * 
 * @author sufj
 *
 */
@RestController
@RequestMapping(value = "/hospital", produces = "text/json;charset=UTF-8")
public class HospitalApi extends BaseController {

	@Resource
	HospitalService hospitalService;
	
	@RequestMapping(value = "/getHospitalList", method = RequestMethod.GET)
	@ApiOperation(value = "获取所有医院", notes = "{'city':'所在城市',"+
	"'status':'医院签约状态0：正常（默认） 1：解除签约'}", response = HospitalVo.class)
	//json样例：{"city":"成都","status":"0"}
	public String getHospitalList(@RequestParam String city,@RequestParam String status){
		HospitalEntity entity = new HospitalEntity();
		entity.setCity(city);
		entity.setStatus(status);
		return JsonUtils.getJson(BaseJsonVo.success(hospitalService.getHospitalList(entity)));
	}
	

	@RequestMapping(value = "/getHospitalDetail", method = RequestMethod.GET)
	@ApiOperation(value = "获取医院详情", notes = "{'id':'id'}", response = BaseJsonVo.class)
	public String getHospitalDetail(@RequestParam int id){
		return JsonUtils.getJson(BaseJsonVo.success(hospitalService.getHospitalDetail(id)));
	}
	
	@RequestMapping(value = "/getHospitalByName", method = RequestMethod.GET)
	@ApiOperation(value = "通过名称查询医院", notes = "{'name':'医院名称'}", response = HospitalVo.class)
	public String getHospitalByName(@RequestParam String name){
		
		HospitalVo vo = new HospitalVo();
		/**
		  本地tomcat编码和服务器不一致
		String hospital = null;
		try {
			hospital = new String(name.getBytes("ISO-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			
		}
		* 
		 */
		BeanUtils.copyProperties(hospitalService.getHospitalByName(name), vo);
		return JsonUtils.getJson(BaseJsonVo.success(vo));
	}
}
